package com.thoughtworks.android.androsphere.service.auth;

public class ClientLoginAuthService {
    String token = null;
    private ClientLoginAuthTokenGenerator tokenGenerator;

    public ClientLoginAuthService(ClientLoginAuthTokenGenerator tokenGenerator) {
        this.tokenGenerator = tokenGenerator;
    }

    public String getAuthToken(boolean forceRegenerate) {
        return forceRegenerate ? generateAndSaveNewToken() : getAuthToken();
    }

    private String getAuthToken() {
        return token != null ? token : generateAndSaveNewToken();
    }

    private String generateAndSaveNewToken() {
        return (token = tokenGenerator.generate());
    }
}
